package com.apr.controller;

import com.apr.bean.Employee;
import com.apr.bean.ResultBean;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @CrossOrigin：支持跨域
 */

//@CrossOrigin
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/get1")
    public ResultBean get1(String data) {
        System.out.println("TestController get1()");
        return new ResultBean("get1 OK");
    }

    @PostMapping("/postJson")
    public ResultBean postJson(@RequestBody Employee employee) {
        System.out.println("TestController postJson()");
        return new ResultBean("postJson : " + employee.getLastName());
    }

    @GetMapping("/testCookie")
    public ResultBean testCookie(@CookieValue("cookie1") String cookie1) {
        System.out.println("TestController testCookie()");
        return new ResultBean("testCookie : " + cookie1);
    }

    @GetMapping("/testHeader")
    public ResultBean testHeader(@RequestHeader("x-header1") String header1,
        @RequestHeader("x-header2") String header2) {
        System.out.println("TestController testHeader()");
        return new ResultBean("testHeader : " + header1 + " " + header2);
    }
}
